********************************************************************************
* Exporting representativeness table for multi-country COVID paper (NPL1 sample)
* last updated: 2020-10-22
* Salim Benhachmi
********************************************************************************

use "$da/NPL1_reptable", clear

gen variable = ""
gen mean_covid = ""
gen mean_fullSamp = ""
loc i = 0
foreach var of varlist rural hhsize respfemale educSec totInc {
loc ++ i
sum `var' if  contacted_COVID == 1 
loc mean_covid = round(`r(mean)',0.01) 
if "`var'" == "totInc" loc mean_covid = round(`r(mean)',1)
if "`var'" == "totInc" loc mean_covid: di %10.0fc `mean_covid'
replace mean_covid = "`mean_covid'" if _n == `i'

sum `var'
loc mean_fullSamp = round(`r(mean)',0.01) 
if "`var'" == "totInc" loc mean_fullSamp = round(`r(mean)',1)
if "`var'" == "totInc" loc mean_fullSamp: di %10.0fc `mean_fullSamp'
replace mean_fullSamp = "`mean_fullSamp'" if _n == `i'

replace variable = "`var'" if _n == `i' 

}

keep variable mean_*

drop variable

rename (mean_covid mean_fullSamp) (sample_avg population_avg )
destring, replace
drop if sample_avg == .

gen sample_avg_weight = .

gen national_avg = .

replace national_avg = 0.79 in 1
replace national_avg = 4.80 in 2
replace national_avg = 0.54 in 3
replace national_avg = 0.29 in 4
replace national_avg = 457 in 5

order sample_avg sample_avg_weight population_avg national_avg

export excel using "$dtab/Representativeness Table.xlsx", sheetmodify cell(C78)

********************************************************************************
